package com.liujit.bms.pc.controller;

import com.liujit.bms.pc.domain.query.BlogArticleQuery;
import com.liujit.bms.pc.domain.result.BlogArticleResult;
import com.liujit.bms.pc.service.BlogArticleService;
import com.liujit.common.domain.result.PageBean;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Description: 首页
 * @Author: liujun
 * @Date: 2021/7/3 2:41 下午
 */
@RequiredArgsConstructor
@Controller
public class IndexController {

    private final BlogArticleService blogArticleService;

    @ApiOperation(value = "首页")
    @RequestMapping
    public String index(Model model, Integer page, String title) {
        BlogArticleQuery query = new BlogArticleQuery();
        query.setPageNumber(page);
        query.setTitle(title);
        PageBean<BlogArticleResult> pageBean = blogArticleService.getPage(query);
        model.addAttribute("total", pageBean.getTotal());
        model.addAttribute("page", pageBean.getPageNumber());
        model.addAttribute("pages", pageBean.getPages());
        model.addAttribute("articleList", pageBean.getRows());
        return "index";
    }
}
